package geocoding;

import java.sql.Timestamp;
import java.util.Comparator;

public class TripStopComparator implements Comparator<TripStop> {
	public TripStopComparator() {
		
	}
	
	static public double diffInMinutes(int hour, int minute, int second, TripStop t) {
		int [] tTime = new int [3];
		String [] tmp;
		int secs, t_secs;
		
		tmp = t.getStopTime().split(":");
		tTime[0] = Integer.valueOf(tmp[0]);
		tTime[1] = Integer.valueOf(tmp[1]);
		tTime[2] = Integer.valueOf(tmp[2]);
		
		secs = (hour*60 + minute)*60 + second;
		t_secs = (tTime[0]*60 + tTime[1])*60 + tTime[2];
		
		return (secs - t_secs)/60.0;
	}
	
	static public double addDurationInMinutes(int hour, int minute, int second, TripStop t) {
		int [] tTime = new int [3];
		int secs, t_secs;
		
		secs = (hour*60 + minute)*60 + second;
		t_secs = t.getT();
		
		return (secs + t_secs)/60.0;
	}
	
	public static int [] secondsToArray(int seconds) {
		int [] res = new int[3];
		
		res[2] = seconds % 60;
		seconds = seconds/60;
		
		res[1] = seconds % 60;
		seconds = seconds/60;
		
		res[0] = seconds;
		
		return res;
	}
	
	static public double addInMinutes(int hour, int minute, int second, TripStop t) {
		int [] tTime = new int [3];
		String [] tmp;
		int secs, t_secs;
		
		tmp = t.getStopTime().split(":");
		tTime[0] = Integer.valueOf(tmp[0]);
		tTime[1] = Integer.valueOf(tmp[1]);
		tTime[2] = Integer.valueOf(tmp[2]);
		
		secs = (hour*60 + minute)*60 + second;
		t_secs = (tTime[0]*60 + tTime[1])*60 + tTime[2];
		
		return (secs + t_secs)/60.0;
	}

	static public double addInSeconds(int hour, int minute, int second, TripStop t) {
		int [] tTime = new int [3];
		String [] tmp;
		int secs, t_secs;
		
		tmp = t.getStopTime().split(":");
		tTime[0] = Integer.valueOf(tmp[0]);
		tTime[1] = Integer.valueOf(tmp[1]);
		tTime[2] = Integer.valueOf(tmp[2]);
		
		secs = (hour*60 + minute)*60 + second;
		t_secs = (tTime[0]*60 + tTime[1])*60 + tTime[2];
		
		return (secs + t_secs);
	}
	public int compare(TripStop o1, TripStop o2) {
		int [] o1Time = new int [3];
		int [] o2Time = new int [3];
		String [] tmp;
		
		tmp = o1.getStopTime().split(":");
		o1Time[0] = Integer.valueOf(tmp[0]);
		o1Time[1] = Integer.valueOf(tmp[1]);
		o1Time[2] = Integer.valueOf(tmp[2]);
		
		tmp = o2.getStopTime().split(":");
		o2Time[0] = Integer.valueOf(tmp[0]);
		o2Time[1] = Integer.valueOf(tmp[1]);
		o2Time[2] = Integer.valueOf(tmp[2]);
		
		if (o1Time[0] < o2Time[0]) return -1;
		else if (o1Time[0] > o2Time[0]) return 1;
		else {
			if (o1Time[1] < o2Time[1]) return -1;
			else if (o1Time[1] > o2Time[1]) return 1;
			else {
				if (o1Time[2] < o2Time[2]) return -1;
				else if (o1Time[2] > o2Time[2]) return 1;
				else return 0;
			}
		}
	}
}
